package com.sam.query.mould.simple.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sam.core.dao.jdbc.JdbcDao;
import com.sam.core.domain.SysConfig;
import com.sam.query.mould.simple.dao.MouldSimpleDao;
import com.sam.query.mould.simple.domain.Config;
import com.sam.query.mould.simple.domain.Form;
import com.sam.query.mould.simple.domain.Mould;
import com.sam.query.mould.simple.domain.MouldClass;
import com.sam.query.mould.simple.domain.QueryResult;
import com.sam.query.mould.simple.service.MouldSimpleService;

/**
 * @project mould
 * @author Sam
 * @version
 * @date Nov 10, 2009 5:00:39 PM
 */
@Service("mouldSimpleService")
@Transactional
@SuppressWarnings("unchecked")
public class MouldSimpleServiceImpl implements MouldSimpleService {
	@Autowired
	private MouldSimpleDao mouldSimpleDao;
	@Autowired
	private JdbcDao jdbcDao;

	/*
	 * (non-Javadoc)
	 * @see com.sam.query.mould.simple.service.MouldSimpleService#queryMouldInfo(com.sam.query.mould.simple.domain.Form)
	 */
	public QueryResult queryMouldInfo(Form form) {
		SysConfig sysConfig = jdbcDao.loadSysConfig();
		Config config = new Config();
		config.setCalculateWay(sysConfig.getCalculateWay());
		config.setPartOrder(sysConfig.getPartOrder());
		config.setPartOrderDirection(sysConfig.getPartOrderDirection());
		config.setIsByOperationOrderID(sysConfig.getDisplayByOperationOrderID());
		config.setDelayBenchmark(sysConfig.getDelayBenchmark());
		config.setShowTime(sysConfig.getShowOperationTime());
		int num = mouldSimpleDao.queryMould(form);
		System.out.println(num);
		List<Mould> list = new ArrayList<Mould>();

		try {
			list = mouldSimpleDao.queryMouldState(config, form);
		} catch (Exception e) {
			e.printStackTrace();
		}

		QueryResult result = new QueryResult();
		Mould mould = new Mould();
		if (list.size() == 1) {
			result.setMouldList(list);
			mould = list.get(0);
		}
		result.setMould(mould);
		return result;
	}

	/*
	 * (non-Javadoc)
	 * @see com.sam.query.mould.simple.service.MouldSimpleService#queryMouldClassList()
	 */
	public List<MouldClass> queryMouldClassList() {
		return mouldSimpleDao.queryMouldClassList();
	}

	/*
	 * (non-Javadoc)
	 * @see com.sam.query.mould.simple.service.MouldSimpleService#queryMouldList()
	 */
	public List<Mould> queryMouldList() {
		return mouldSimpleDao.queryMouldList();
	}

}
